|
Download
FAQ History |
|
API
Search Feedback |
EJB-Tier Security
The following sections describe declarative and programmatic security mechanisms that can be used to protect resources in the EJB tier. The protected resources include methods of enterprise beans that are called from application clients, Web components, or other enterprise beans.
You can protect EJB-tier resources by doing the following:
For information about mapping roles to J2EE users and groups, see Mapping Roles to Users and Groups.
Declaring Method Permissions
After you've defined the roles (see Security Roles), you can define the method permissions of an enterprise bean. Method permissions indicate which roles are allowed to invoke which methods. You can define method permissions in different ways.
- You can apply method permissions to all of the methods of the specified enterprise bean's home, component, and/or Web service endpoint interfaces.
- You can apply method permissions to the specified method of the specified enterprise bean. If the enterprise bean contains multiple methods with the same method name, the method permission applies to all of the methods.
- If the enterprise bean contains multiple methods with the same method name but the methods have different method parameters (such as
create(a,b)andcreate(a,b,c)), you can apply method permissions by specifying the method parameters.Using Programmatic Security in the EJB Tier
Programmatic security in the EJB tier consists of the
getCallerPrincipaland theisCallerInRolemethods. You can use thegetCallerPrincipalmethod to determine the caller of the enterprise bean, and theisCallerInRolemethod to determine if the caller has the specified role.The
getCallerPrincipalmethod of theEJBContextinterface returns thejava.security.Principalobject that identifies the caller of the enterprise bean. (In this case, a principal is the same as a user.) In the following example, thegetUsermethod of an enterprise bean returns the name of the J2EE user that invoked it:You can determine whether an enterprise bean's caller belongs to the
Customerrole.Unauthenticated User Name
Web applications accept unauthenticated Web clients and allow these clients to make calls to the EJB container. The EJB specification requires a security credential for accessing EJB methods. Typically, the credential will be that of a generic unauthenticated user.
|
Download
FAQ History |
|
API
Search Feedback |
All of the material in The J2EE 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.